remote-add: Add --set=KEY=VALUE option
authorColin Walters <walters@verbum.org>
Sat, 28 Sep 2013 16:00:16 +0000 (12:00 -0400)
committerColin Walters <walters@verbum.org>
Sat, 28 Sep 2013 16:00:16 +0000 (12:00 -0400)
This can be used to add a remote and set e.g. tls-permissive=true, or
gpgverify=false.

src/ostree/ot-builtin-remote.c
tests/test-basic.sh

index 98a8b4b30a176757e30996eaef10b1223f9cf7e9..1f72883a7c915604db74e3174289fa5be998028e 100644 (file)
 #include "ostree.h"
 #include "otutil.h"
 
+char **opt_set;
+
 static GOptionEntry options[] = {
+  { "set", 0, 0, G_OPTION_ARG_STRING_ARRAY, &opt_set, "Set config option KEY=VALUE for remote", "KEY=VALUE" },
   { NULL }
 };
 
@@ -40,6 +43,24 @@ usage_error (GOptionContext *context, const char *message, GError **error)
                        message);
 }
 
+static gboolean
+parse_keyvalue (const char  *keyvalue,
+                char       **out_key,
+                char       **out_value,
+                GError     **error)
+{
+  const char *eq = strchr (keyvalue, '=');
+  if (!eq)
+    {
+      g_set_error (error, G_IO_ERROR, G_IO_ERROR_FAILED,
+                   "Missing '=' in KEY=VALUE for --set");
+      return FALSE;
+    }
+  *out_key = g_strndup (keyvalue, eq - keyvalue);
+  *out_value = g_strdup (eq + 1);
+  return TRUE;
+}
+
 gboolean
 ostree_builtin_remote (int argc, char **argv, OstreeRepo *repo, GCancellable *cancellable, GError **error)
 {
@@ -69,6 +90,7 @@ ostree_builtin_remote (int argc, char **argv, OstreeRepo *repo, GCancellable *ca
   if (!strcmp (op, "add"))
     {
       char *key;
+      char **iter;
       if (argc < 4)
         {
           usage_error (context, "NAME and URL must be specified", error);
@@ -81,6 +103,19 @@ ostree_builtin_remote (int argc, char **argv, OstreeRepo *repo, GCancellable *ca
 
       key = g_strdup_printf ("remote \"%s\"", argv[2]);
       g_key_file_set_string (config, key, "url", argv[3]);
+
+      for (iter = opt_set; iter && *iter; iter++)
+        {
+          const char *keyvalue = *iter;
+          gs_free char *subkey = NULL;
+          gs_free char *subvalue = NULL;
+
+          if (!parse_keyvalue (keyvalue, &subkey, &subvalue, error))
+            goto out;
+
+          g_key_file_set_string (config, key, subkey, subvalue);
+        }
+
       if (branches->len > 0)
         g_key_file_set_string_list (config, key, "branches",
                                     (const char *const *)branches->pdata,
index 4c7e056df24040a8e646d1b6bcf529fc6cd0395c..8c32b097c2149d5de861b4ef042137d00551fff3 100755 (executable)
@@ -299,3 +299,9 @@ ${CMD_PREFIX} ostree --repo=repo2 init
 ${CMD_PREFIX} ostree --repo=repo2 pull-local repo
 echo "ok pull-local after commit metadata"
 
+cd ${test_tmpdir}
+${CMD_PREFIX} ostree --repo=repo remote --set=tls-permissive=true add aremote http://remote.example.com/repo testos/buildmaster/x86_64-runtime
+assert_file_has_content repo/config 'tls-permissive=true'
+assert_file_has_content repo/config 'remote\.example\.com'
+echo "ok remote add with set"
+